package br.com.sovi.gwt.client.component.themechanger;

import com.gwtext.client.data.Record;
import com.gwtext.client.data.SimpleStore;
import com.gwtext.client.data.Store;
import com.gwtext.client.util.CSS;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;

public class ThemeChangerComboBox extends ComboBox {

	public ThemeChangerComboBox() {

		final Store store = new SimpleStore(new String[] { "theme", "label" },
				new Object[][] {
						new Object[] { "extjs/resources/css/ext-all.css",
								"Padrão" },
						new Object[] { "extjs/resources/css/xtheme-gray.css",
								"Gray" },
						new Object[] { "extjs/resources/css/xtheme-black.css",
								"Black" },
						new Object[] {
								"extjs/resources/css/xtheme-darkgray.css",
								"Dark Gray" },
						new Object[] {
								"extjs/resources/css/xtheme-slickness.css",
								"Slickness" } 
						});

		store.load();

		setFieldLabel("Select Theme");
		setEditable(false);
		setStore(store);
		setDisplayField("label");
		setForceSelection(true);
		setTriggerAction(ComboBox.ALL);
		setValue("Gray");
		setFieldLabel("Switch theme");
		addListener(new ComboBoxListenerAdapter() {
			public void onSelect(ComboBox comboBox, Record record, int index) {
				String theme = record.getAsString("theme");
				CSS.swapStyleSheet("theme", theme);
			}
		});

		setWidth("200px");
	}
}
